//
//  TJHomeViewController.m
//  TJSinaWeiBo_OC
//
//  Created by 唐后能 on 16/4/13.
//  Copyright © 2016年 itheima. All rights reserved.
//

#import "TJHomeViewController.h"
#import "UIBarButtonItem+Extension.h"
#import "TJTitleBtn.h"
#import "TJStatusViewModel.h"
#import "MBProgressHUD+PKX.h"

#pragma mark - 延展属性.
@interface TJHomeViewController ()<UITableViewDataSource,UITableViewDelegate>

// 微博模型数组.
@property (nonatomic, strong) NSArray *statusModles;

@end

#pragma mark - 实现.
@implementation TJHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // 设置导航栏.
    [self setNavBtn];
    
    // 请求网络数据.
    [self loadStatus];
    
    // 设置tableView.
    [self setupTableView];
}

#pragma mark - 设置tableView.
-(void)setupTableView{

    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    // 去掉分割线.
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    
}

#pragma mark - tableView的数据源/代理方法.
// 返回多少行.
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.statusModles.count;
}
// 每个cell长啥样
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    return nil;
}


#pragma mark - 网络请求数据.
- (void)loadStatus{

    [[TJStatusViewModel shareStatusViewModel] loadStatusWithsince_id:0 andMax_id:0 andCallBack:^(NSError *error, NSArray *statuses) {
        if (error != nil) {
            [MBProgressHUD showError:@"加载微博数据失败!"];
        }
        // 给微博模型属性赋值.
        self.statusModles = statuses;
    }];
}

#pragma mark - 设置导航栏.
- (void)setNavBtn{

    // 左边按钮.
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem normalImgName:@"navigationbar_friendsearch" andHighlightImgName:@"navigationbar_friendsearch_highlighted" andTarget:self action:@selector(addFriendBtnClicked)];
    
    // 右边按钮.
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem normalImgName:@"navigationbar_pop" andHighlightImgName:@"navigationbar_pop_highlighted" andTarget:self action:@selector(saoyisaoBtnClicked)];
    
    // 中间按钮.
     self.navigationItem.titleView =[[TJTitleBtn alloc] initWithImgName:@"navigationbar_arrow_up" andTitle:@"XXX" andTarget:self action:@selector(titleBtnClicked:)];
}

// 导航栏按钮点击事件.
- (void)addFriendBtnClicked {

    TJLog(@"添加好友");
}
- (void)saoyisaoBtnClicked {
    
    TJLog(@"扫一扫");
}
- (void)titleBtnClicked:(UIButton *)btn {

    btn.selected = !btn.selected;
    if (btn.selected) {
        
        [UIView animateWithDuration:0.25 animations:^{
            
            btn.imageView.transform = CGAffineTransformMakeRotation(M_PI-0.0001);
        }];
    }else{
     
        [UIView animateWithDuration:0.25 animations:^{
            
            btn.imageView.transform = CGAffineTransformIdentity;
        }];
    }
}

#pragma mark - 懒加载.
-(NSArray *)statusModles {

    if (_statusModles==nil) {
        _statusModles = [NSArray array];
    }
    return _statusModles;
}

@end
